import mongoose from "mongoose"
import { ENV_VARS } from "./envVars.js"

export const connectDB = async () => {
    try {
        const conn = await mongoose.connect(ENV_VARS.MONGODB_URI, {
            // NOTE: this fix: Error connection to mongodb: Authentication failed.
            authSource: 'admin',
        })
        console.log("mongodb connected: " + conn.connection.host + conn.connection.port)
    } catch (error) {
        console.log("Error connecting to mongodb: " + error.message)
        process.exit(1)
    }
}
